const express = require('express');
const router = express.Router();
const common = require('./common');

const connection = common.mysqlConfig;

router.post('/', (req, res, next) => {
  // 公章 id
  const id = req.body.id;
  // 获取员工 id
  const userID = req.headers.token;
  // 获取新增时间
  const date = common.DateFomart(new Date(), 'yyyy-mm-dd HH:mm');
  // 公会内容
  const content = req.body.content
  // 公会内容描述
  const preview = common.matchReg(content);
  // const preview = content.slice(0,50);
  // 公会标题
  const title = req.body.title

  // 发送人
  const sender = req.body.sender
  // 上传附件
  const attachment = JSON.stringify(req.body.attachment) 
  const sql = `UPDATE MESSAGE_LIST SET userID='${userID}', title='${title}', content='${content}', sendTime='${date}',
    sender='${sender}', preview='${preview}', attachment='${attachment}' WHERE ID = '${id}'`;
  connection.query(sql, (err, result) => {
    const data = common.resCommon1(err, result);
    res.json(data);
  })  
})

module.exports = router;